package com.zjdiepu.www.biz.system;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zjdiepu.www.base.core.BaseService;
import com.zjdiepu.www.common.util.DateUtil;
import com.zjdiepu.www.dao.system.OtherHolidaysMapper;
import com.zjdiepu.www.ibiz.system.IOtherHolidaysService;
import com.zjdiepu.www.model.system.dto.OtherHoliday;
import com.zjdiepu.www.model.system.ext.OtherHolidayExt;
import com.zjdiepu.www.util.ExceptionHelper;
@Service
public class OtherHolidaysServiceImpl extends BaseService implements IOtherHolidaysService{

	@Autowired
	private OtherHolidaysMapper otherHolidaysMapper;

	@Override
	public void insert(List<OtherHoliday> lists) {
		otherHolidaysMapper.insert(lists);
	}

	@Override
	public int countByExt(OtherHolidayExt otherHolidayExt) {
		return otherHolidaysMapper.countByExt(otherHolidayExt);
	}

	@Override
	public List<OtherHoliday> selectByExt(OtherHolidayExt otherHolidayExt) {
		return otherHolidaysMapper.selectByExt(otherHolidayExt);
	}

	@Override
	public void update(OtherHoliday otherHoliday) {
		otherHolidaysMapper.update(otherHoliday);
		
	}

	@Override
	public List<OtherHoliday> findDateTypeList(List<OtherHoliday> listDate) {
		return otherHolidaysMapper.findDateTypeList(listDate);
	}
	
	@Override
	public Date getNextWorkDate(Date inputDate, String dateType, int nextDates) {
		if(nextDates < 1){
			ExceptionHelper.thow("9999","预警时间必须为大于0的整数");
		}
		OtherHolidayExt otherHolidayExt = new OtherHolidayExt();
		otherHolidayExt.setDateType(dateType);//工作日
		otherHolidayExt.setDateHStart(DateUtil.truncAndAddDays(inputDate, 0));//今天开始计算
		otherHolidayExt.setNum(nextDates - 1);
		Date nextWorkDate = otherHolidaysMapper.getNextWorkDate(otherHolidayExt);
		return nextWorkDate;
	}
}
